package com.flyduck.vueshop.order.h5.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flyduck.vueshop.common.core.lang.Result;
import com.flyduck.vueshop.common.mybatis.base.BaseController;
import com.flyduck.vueshop.common.redis.annotation.NoRepeatSubmit;
import com.flyduck.vueshop.common.sotoken.annotation.Login;
import com.flyduck.vueshop.order.h5.service.H5OrderService;
import com.flyduck.vueshop.order.h5.vo.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: vueshop
 * @description:
 * @author: flyduck
 * @create: 2024-05-20 20:40
 **/
@RestController
@RequestMapping("/order/h5/order")
public class H5OrderController extends BaseController {

    @Resource
    private H5OrderService h5OrderService;

    @Login
    @PostMapping("previewOrder")
    public Result<H5OrderPreviewRespVO> previewOrder(@RequestBody H5OrderPreviewReqVO h5OrderPreviewReqVO){
        H5OrderPreviewRespVO appOrderPreviewRespVO = h5OrderService.previewOrder(h5OrderPreviewReqVO);
        return Result.success(appOrderPreviewRespVO);
    }

    @Login
    @NoRepeatSubmit
    @PostMapping("createOrder")
    public Result<String> createOrder(@RequestBody H5OrderCreateReqVO h5OrderCreateReqVO){
        String orderSn = h5OrderService.createOrder(h5OrderCreateReqVO);
        return Result.success(orderSn);
    }

    @Login
    @GetMapping("/getOrderTotalCount")
    public Result<H5OrderTotalCountRespVO> getOrderTotalCount(){
        H5OrderTotalCountRespVO h5OrderTotalCountRespVO = h5OrderService.getOrderTotalCount();
        return Result.success(h5OrderTotalCountRespVO);
    }

    @Login
    @GetMapping("/getOrderPageByStatus")
    public Result<Page<H5OrderRespVO>> getOrderPageByStatus(Integer status){
        return Result.success(h5OrderService.getOrderPageByStatus(getPage(),status));
    }

    @Login
    @GetMapping("/getOrderDetailsById/{id}")
    public Result<H5OrderDetailsRespVO> getOrderDetailsById(@PathVariable("id") Long id){
        return Result.success(h5OrderService.getOrderDetailsById(id));
    }

    @Login
    @PostMapping("/cancelOrderById/{id}")
    public Result<Void> cancelOrderById(@PathVariable("id")Long id){
        h5OrderService.cancelOrderById(id);
        return Result.success();
    }

    @Login
    @PostMapping("/deleteById/{id}")
    public Result<Void> deleteById(@PathVariable("id")Long id){
        h5OrderService.deleteById(id);
        return Result.success();
    }



    @Login
    @PostMapping("/confirmOrderById/{id}")
    public Result<Void> confirmOrderById(@PathVariable("id")Long id){
        h5OrderService.confirmOrderById(id);
        return Result.success();
    }
}
